const app = getApp()
import BaseModel from '../../utils/common.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",//客户id
    vipTypeData:"",//vip分类
    selectedList:"",//选中的数据
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getVipTypeData(); //获取vip分类
    this.getVipAlreadyData();
  },
  /*确定*/
  click_sure:function(){
    this.getUserLabelData();
  },
  /*复选框选择事件*/
  checkboxChange: function(e) {
    var selectedData = e.detail.value.toString()
    this.setData({
      selectedList: selectedData
    })
  },
  //获取VIP分类数据
  getVipTypeModel: new BaseModel({
    url: "employees/Vip",
    needAjaxLoading: true,
    method: "get",
    loadingText: "玩命加载中"
  }),
  getVipTypeData() {
    this.getVipTypeModel
        .fetch({
          user_id:this.data.id
        })
        .then(res => {
          //成功
          this.setData({
            vipTypeData:res.data
          });
        })
        .catch(res => {
          //失败 2018-12-20 00:00:00
        })
  },
  //获取已获取的vip
  getVipAlreadyModel: new BaseModel({
    url: "employees/userVip",
    needAjaxLoading: true,
    method: "get",
    loadingText: "玩命加载中"
  }),
  getVipAlreadyData() {
    this.getVipAlreadyModel
        .fetch({
          user_id:this.data.id,
          type:1
        })
        .then(res => {
          //成功
          this.setData({
            selectedList:res.data
          });
        })
        .catch(res => {
          //失败 2018-12-20 00:00:00
        })
  },
  //修改标签
  getUserLabelModel:new BaseModel({
    url: "employees/updataVip",
    needAjaxLoading:true,
    method: "get",
    loadingText:"玩命加载中"
  }),
  getUserLabelData(){
    this.getUserLabelModel
        .fetch({
          user_id:this.data.id,
          vip_id:this.data.selectedList,
        })
        .then(res => {
          //成功
          wx.navigateBack({
            delta: 1
          })
        })
        .catch(res => {
          //失败 2018-12-20 00:00:00
        })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getVipTypeData(); //获取vip分类
    wx.stopPullDownRefresh(); //停止下拉
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})